

class Itinerary(object):

    def __init__(self, 
        legs,
        date='', startTime='', endTime='', duration='', distance='', 
        numberOfTransfers='', numberOfTripLegs='', 
        walkingTime='', transitTime='', waitingTime='',
    ):
        self.legs=legs
        self.date=date
        self.startTime=startTime
        self.endTime=endTime
        self.duration=duration
        self.distance=distance
        self.numberOfTransfers=numberOfTransfers
        self.numberOfTripLegs=numberOfTripLegs
        self.walkingTime=walkingTime
        self.transitTime=transitTime
        self.waitingTime=waitingTime

    def set_values_from_element(self, element, ns):
        if element:
            for e in element:
                tag = e.tag.replace(ns, '')
                setattr(self, tag, e.text)

class Trip(object):

    def __init__(self, 
        ws_url = '', map_url = '', 
        itineraries=[],
        error=False, message='' 
    ):
        self.ws_url = ws_url
        self.map_url = map_url
        self.error=error
        self.message=message
        self.itineraries=itineraries


    @classmethod
    def find_elements(cls, el_list, targets, ns):
        retVal = {}
        for e in el_list:
            name = e.tag.replace(ns, '')
            if name in targets:
                retVal[name] = e

        return retVal

    @classmethod
    def find_element_value(cls, elements, name, ns):
        el = cls.find_elements(elements, [name], ns)
        return el[name].text

    @classmethod
    def find_stopid_from_element(cls, stopEl, stop_id_name, ns):
        return cls.find_element_value(stopEl, stop_id_name, ns)

    @classmethod
    def find_in_tree(cls, tree, name, ns):
        search = "{0}{1}".format(ns, name)
        return tree.getroot().find(search)


